package com.example.wendao.view.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.wendao.R;
import com.example.wendao.view.adapter.ViewInfoAgreeAdapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public  class ViewPagerNavInfoAgreeFragment extends Fragment {


    private ViewPager2 vp;

    private TabLayout tb;

    private ViewInfoAgreeAdapter viewInfoAgreeAdapter ;
    public ViewPagerNavInfoAgreeFragment() {}
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //binding = DataBindingUtil.inflate(inflater, R.layout.fragment_viewpager_nav_test, container, false);
        View view = inflater.inflate(R.layout.fragment_infoagree_paging, container, false);
        vp = view.findViewById(R.id.infoagree_view_pager);
        tb = view.findViewById(R.id.infoagree_tabs);

        viewInfoAgreeAdapter = new ViewInfoAgreeAdapter(this);
        // 设置ViewPager2适配器
        vp.setAdapter(viewInfoAgreeAdapter);

        // 绑定 TabLayout 与 ViewPager2，第三个参数设置tab的图标、文本等参数
        new TabLayoutMediator(tb, vp,
                (tab, position) -> {
                    tab.setText(getTabTitle(position));
                }).attach();

        return view;
    }


    private List<String> titles = new ArrayList<>();

    {
        Collections.addAll(titles, "新闻", "论坛");
    }

    private String getTabTitle(int position) {
        return titles.get(position);
    }
}
